<template> 
<div class="app-container">
    <div class="ces-main">



      <el-form
         
          :model="FormData"
          :inline="true"
    
          label-position="right"
          label-width="120px"
        >
        
         
          <el-form-item  style="height:5px">

            <el-button
              type="primary"
              size="mini"
              icon="el-icon-tickets"
              @click="confirmData(1)"
              >生成条码</el-button
            >
          </el-form-item>
         
 <el-form-item  style="height:5px">

  <!-- <el-button
              type="primary"
              size="mini"
              icon="el-icon-tickets"
             @click="PrintDesign()"
              >设计</el-button
            > -->
          </el-form-item>
          <el-form-item style="height:5px">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-check"
              @click="handleClose()"
               @handlechange="handlechange"
              >关闭</el-button
            >
          </el-form-item>


        </el-form>    

    <span
          style="
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            display: inline-block;
            width: 100%;
            padding: 3px 0 5px 0;
          "
        >
          <span>条码打印</span>
          <span style="margin-left: 10px">
            <svg-icon v-if="this.FormData.Status == 0||this.FormData.Status == null" icon-class="Editing" />
            <svg-icon v-if="this.FormData.Status == 1" icon-class="ingAudit" />
            <svg-icon v-if="this.FormData.Status == 2" icon-class="Finish" />
          </span>
        </span>
        
<el-form :model="FormData" label-width="90px" >
       <Mian-Form 
        ref="refFormData"
        labelWidth = '100px' 
        :FormData = 'FormData'
         :tableCols = 'FormCols'
          :StepSN = 'StepSN'
        @handlechange="handlechange"
        ></Mian-Form >
      </el-form>


 <el-form
        :inline="true"
        :model="Search"
        class="demo-form-inline"
        size="mini"
      >
      </el-form>
  
 <section class="ces-handle">
      <!-- <el-button v-if="this.StepSN == 0"
              type="primary"
              size="mini"
              @click="handleOpen('PrdNo')"
              icon="el-icon-tickets"
              >添加产品</el-button> -->

             
    </section>
        <ces-table 
        size='mini'
        ref="reftableData"
        :refs='reftableData'
        :isSelection='false'
        :isIndex='true'
        :isSearch='false'
        :isHandle='false'
        :Isfunfail='this.StepSN==0?true:false'
        :IsfunEdit='true'
        :funEditName='BOM'
        :StepSN = this.StepSN
        :WFStepSN='WFStepSN'
        :tableData='tableData' 
        :tableCols='tableCols' 
        @handleDelete="delData"
       @handleEdit='Printorder'
        >
        </ces-table>
        </div>


<el-main style="margin: 1px 10px">
          <span class="blueColor" style="font-size: 15px; font-weight: blod; padding: 10px"
            >审核明细：</span
          >

          <el-timeline :reverse="true" ref="ListLog" :model="ListLog">
            <el-timeline-item
              v-for="(activity, index) in ListLog"
              :key="index"
              :timestamp="activity.CreateDateTime"
            >
              {{ activity.Remark }}
            </el-timeline-item>
          </el-timeline>
        </el-main>


    <el-dialog
              v-if="dialogFormVisible"
              :visible.sync="dialogFormVisible"
              :title="人员资料"
              
              width="800px"
            >
              <el-form :model="name" label-width="80px" label-position="left">
                <v-AccountOpen
                  :ParmType="ParmType"
                  @FunRowAdd="FunrRowsAdd"
                ></v-AccountOpen>
              </el-form>
            </el-dialog>


            <el-dialog
              v-if="dialogCUSTVisible"
              :visible.sync="dialogCUSTVisible"
              :title="客户资料"
              
              width="800px"
            >
              <el-form :model="name" label-width="80px" label-position="left">
                <v-CUSTOpen
                  :ParmType="ParmType"
                  :CUSTtype='1'
                  @FunRowAdd="FunrRowsAdd"
                ></v-CUSTOpen>
              </el-form>
            </el-dialog>


               <el-dialog
              v-if="dialogPRDTVisible"
              :visible.sync="dialogPRDTVisible"
              :title="料品资料"
              
              width="800px"
            >
              <el-form :model="name" label-width="80px" label-position="left">
                <v-PRDTOpen
                  :ParmType="ParmType"
                  :Where="ProWhere"
                  @FunRowAdd="FunrRowsAdd"
                ></v-PRDTOpen>
              </el-form>
            </el-dialog>


</div>
</template>

<script>


//引入组件

import cesTable from "../Common//table.vue";
import SearchForm from "../Common//Search.vue";
import MianForm from "../Common//form.vue";
import { PrintDate } from "@/api/Print";
import { funDownload,GetTableColsData,GetFormColsData } from "@/api/Common";
import {UpdateForm,DeleteRow} from '@/api/MesSales/barcode';
import vGetToolBar from "../Common/GetToolBar";
import vAccountOpen from "../Common/AccountOpen";
import vCUSTOpen from "../Common/CUSTOpen";
import vPRDTOpen from "../Common/PRDTOpen";
import { getLodop } from "@/api/LodopFuncs";
export default {
name:"barcodeForm",
 props: {
    inputName: String,
    required: true,
      ProductNo:String,
    required:true,
      OrderNo:String,
    required:true,
  },

    data(){
         //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看
      
        return {
        MenuCode: "A050302",
        tableData:[],//表格数据
        FormData:[],//表格数据
        FormCols:[],//表头数据
        tableCols:[],//表格列数据
        StepSN: -1,
        WFStepSN:'0',
        billID:null,
        ListLog: [],
        IsfunEdit:false,
        Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 13, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "002", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件
      },
     
       cities: [
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ],
       SearchDialog: false,
         DialogBtnMargin: 0,
         dialogVisible: false,
         dialogFormVisible: false,
         dialogCUSTVisible:false,
         dialogPRDTVisible:false,
         ParmType: "",
         ProWhere:" and IDXI='A01'",
          
        }
    },

   components:{ //引入组件后注册组件
    cesTable, 
     SearchForm,
     MianForm,
     vAccountOpen,
     vCUSTOpen,
     vPRDTOpen
   },
   mounted(){

     this.getTableCols()
     this.getDataList()
    
    
   },
    methods:{
        
    
      //读取列配置
        async getTableCols(){
        this.tableCols = [];
        this.FormCols=[];

        const resCols = await  GetFormColsData({InterID:"414"});
        this.FormCols=resCols.data;

        const res = await  GetTableColsData({InterID:"414"});
        this.tableCols=res.data;
                  
         },
        async getDataList() {

 
 

       if (this.OrderNo == null) {
        this.OrderNo = this.$route.query.OrderNo;
      }

       if (this.ProductNo == null) {
        this.ProductNo = this.$route.query.ProductNo;
      }

      const result = await UpdateForm({
        billID: this.OrderNo,
        ProductNo: this.ProductNo,
        IsPostBack: false,
      });

      this.FormData = result.data1.Table[0];
     
      this.tableData = result.data2.Table;
    

      this.ListLog = result.ListLog;
      this.StepSN = result.StepSN;
      
        
        
    
    },OpenFindForm() {
      //打开搜索框
      this.SearchDialog = true;
      //计算外边距
      console.log(this.$refs.searchDialog.offsetHeight);
      this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
    },async confirmData(submit) {
      // 提交数据，需要修改

      const Fresult = true;


      

      if (submit == 1) {

      
        //let flag1 = this.$refs['reftableData'].validateForm(); 

        let flag = this.$refs['refFormData'].validateForm(); 



       
  

    if(flag==false)
     {
          this.$notify({
              title: "不能提交",
              dangerouslyUseHTMLString: true,
              message: "不可为空，不能提交",
              type: "error",
            });
            Fresult = false;
            return false;

      }

    // if(this.tableData.length<=0)
    // {
    //    this.$notify({
    //           title: "不能提交",
    //           dangerouslyUseHTMLString: true,
    //           message: "行没有数据，不能提交",
    //           type: "error",
    //         });
    //         Fresult = false;
    //         return false;

    // }

   }

  let options="保存中...";

if(submit == 1)
{
  options="生成中...";
}else if(submit == 2)
{
   options="审批中...";
}else if(submit == 3)
{
   options="退回中...";
}

  const loading = this.$loading({
          lock: true,
          text: options,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      if (Fresult) {

        this.FormData.Weight=parseFloat(this.FormData.TotalWeight) -parseFloat(this.FormData.TareWeight);
        const result = await UpdateForm({
          HeadDate: JSON.stringify(this.FormData),
          BodyDate: JSON.stringify(this.tableData),
          billID: this.OrderNo,
          ProductNo: this.ProductNo,
          IsPostBack: true,
          submit: submit,
        });
        loading.close();
        this.FormData = result.data1.Table[0];
        this.tableData = result.data2.Table;
        this.ListLog = result.ListLog;
        this.StepSN = result.StepSN;
 
       
        if (result.code === 20000) {
        
          this.dialogVisible = false;
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
      

      //    this.$router.push({
      //   path: "/MesSales/barcodeForm",
      //   query: { billID: this.FormData.OrderNo, IsPostBack: false },
      // });
        //   this.roles = [];
        } else {
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "error",
          });
        }
      }
    },async handleMRPData() {
 
         const result = await MRPData({
          billID: this.FormData.OrderNo,
        });

        if (result.code === 20000) {
        
          this.dialogVisible = false;
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "success",
          });
        
          this.roles = [];
        } else {
          this.$notify({
            title: result.msg,
            dangerouslyUseHTMLString: true,
            message: "",
            type: "error",
          });
        }
    

      },
    handleOpen(name)

    {
      
     
       if(name=="PrdNo")
      {
         this.ParmType = "PrdNo"; //传入参数
        this.dialogPRDTVisible = true;
      }

    },
    FunrRowsAdd: function (Rows, ParmType) {
      //添加人员

      this.multipleTable = Rows[0];

      if(ParmType == "PrdNo")
      {


         for (let v of Rows) {

        this.multipleTable = v;
        let row = {
          PrdNo: this.multipleTable.PrdNo,
          PrdName: this.multipleTable.PrdName,
          SPC: this.multipleTable.SPC,
          UT: this.multipleTable.UT,
          Price: this.multipleTable.Price
        };

        this.tableData.push(row);
     }

      this.dialogPRDTVisible = false;
      } 
    
     
    },
    handlechange(Name)
    {
      if(Name=="TotalWeight"||Name=="TareWeight")
      {
         this.FormData.Weight=parseFloat(this.FormData.TotalWeight) -parseFloat(this.FormData.TareWeight);
      }
        
    },
   async handleEdit(scope) {
      // 修改

//scope.row.OrderNo, ProductNo:scope.row.PrdNo

      
   
      
    },
    handleClose()
    {
       this.$store.dispatch('tagsView/delView', this.$route)
// 返回上一步路由
      this.$router.go(-1)
    }, delData({ $index, row }) {
     this.$confirm('删除操作, 是否继续?', '提示', {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(async () => {
         
           
            this.tableData.splice($index, 1);
           


            if (row.OrderID == null) {
              return false;
            }

            const result = await DeleteRow({
              ID: row.barcode,
              billID: row.barcode,
              types: 1,
              IsPostBack: false,
            });

            this.$message({
              type: "success",
              message: result.msg,
            });
          
        })
        .catch((err) => {
          console.error(err);
        });
    },async PrintDate () 
    {
      // 提交数据，需要修改

     await PrintDate('T20210425002',this.FormData,this.tableData,2);
    
      
    
    } , Printorder1(scope) {
      var LODOP=null;
        LODOP = getLodop();
         this.CreateOnePage1(LODOP,scope);
        LODOP.PRINT_DESIGN();
    }, Printorder(scope) {
        var barCode="";
      var LODOP=null;
        var Num = 1;
        var iCurLine = 80;
        LODOP = getLodop();
        LODOP.PRINT_INIT("条码打印");
        //var rows = $('#PrintInfo').datagrid('getRows');
        //for (var i = 0; i < rows.length; i++) {
        this.CreateOnePage1(LODOP,scope);
        //}
        LODOP.SET_PRINT_PAGESIZE(1, 460, 600, "");
        LODOP.PREVIEW();

    },

       CreateOnePage1(LODOP,scope) {
        //格式：ADD_PRINT_TEXT(Top, Left, Width, Height, strContent)
        var myDate = new Date();
        var mytime="";



        mytime =  myDate.getFullYear()+"-"+(myDate.getMonth()+1).toString()+"-"+myDate.getDate().toString();


 
        var j = 0;
        var iCurLine = 0;

        LODOP.PRINT_INIT("");
LODOP.ADD_PRINT_TEXT(13,30,106,25,"江门千瑞五金");
LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
LODOP.ADD_PRINT_TEXT(149,7,145,20,"条码编号:"+ scope.row.barcode);
LODOP.ADD_PRINT_TEXT(40,8,124,25,"产品:"+scope.row.SPC);
LODOP.ADD_PRINT_TEXT(174,5,126,25,"生产日期:"+mytime);
LODOP.ADD_PRINT_BARCODE(79,76,69,71,"QRCode",scope.row.barcode);
LODOP.SET_PRINT_STYLEA(0,"DataCharset","UTF-8");
LODOP.ADD_PRINT_TEXT(67,8,70,24,"总重:"+scope.row.TotalWeight+"KG");
LODOP.ADD_PRINT_TEXT(93,7,69,24,"皮重:"+scope.row.TareWeight+"KG");
LODOP.ADD_PRINT_TEXT(119,7,69,29,"净重:"+scope.row.Weight+"KG");


        return LODOP;

    }

        
  }
}
</script>

<style lang="scss" scoped>

.app-container {
  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}
.searchDialog ::v-deep .el-dialog__header {
  background: #409eff;
}
.searchDialog ::v-deep .el-dialog__title {
  color: #fff;
}
.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.infoColor {
  font-weight: bold;
  color: #909399;
}
.redColor {
  font-weight: bold;
  color: red;
}
.blueColor {
  font-weight: bold;
  color: #409eff;
}
.orangeColor {
  font-weight: bold;
  color: orange;
}
.greenColor {
  font-weight: bold;
  color: #67c23a;
}
</style>